home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 92 / CDMM92_1.ISO / SOF 2 SDK / sof2sdk-101.msi / _92D6AC311BB48EBA344BBABC89DA6AB0 / _7AB7F60FAF5B48E9AB874CA4F39AEC5E < prev    next >
Encoding:
Text File  |  2002-06-19  |  11.8 KB  |  610 lines

  1. // Copyright (C) 2001-2002 Raven Software.
  2. //
  3. // cg_consolecmds.c -- text commands typed in at the local console, or
  4. // executed by a key binding
  5.  
  6. #include "cg_local.h"
  7. #include "../ui/ui_shared.h"
  8. #include "../ui/ui_public.h"
  9.  
  10. /*
  11. =============
  12. CG_Viewpos_f
  13.  
  14. Debugging command to print the current position
  15. =============
  16. */
  17. static void CG_Viewpos_f (void) 
  18. {
  19.     Com_Printf ("(%i %i %i) : %i\n", (int)cg.refdef.vieworg[0],
  20.         (int)cg.refdef.vieworg[1], (int)cg.refdef.vieworg[2], 
  21.         (int)cg.refdef.viewangles[YAW]);
  22. }
  23.  
  24. /*
  25. =============
  26. CG_ScoresDown_f
  27. =============
  28. */
  29. static void CG_ScoresDown_f( void ) 
  30. {
  31.     if ( cg.scoresRequestTime + 2000 < cg.time ) 
  32.     {
  33.         // the scores are more than two seconds out of data,
  34.         // so request new ones
  35.         cg.scoresRequestTime = cg.time;
  36.         trap_SendClientCommand( "score" );
  37.  
  38.         // leave the current scores up if they were already
  39.         // displayed, but if this is the first hit, clear them out
  40.         if ( !cg.showScores ) 
  41.         {
  42.             cg.showScores = qtrue;
  43.             cg.numScores = 0;
  44.         }
  45.     } 
  46.     else 
  47.     {
  48.         // show the cached contents even if they just pressed if it
  49.         // is within two seconds
  50.         cg.showScores = qtrue;
  51.     }
  52. }
  53.  
  54. /*
  55. =============
  56. CG_ScoresUp_f
  57. =============
  58. */
  59. static void CG_ScoresUp_f( void ) 
  60. {
  61.     if ( cg.showScores ) 
  62.     {
  63.         cg.showScores = qfalse;
  64.         cg.scoreFadeTime = cg.time;
  65.     }
  66. }
  67.  
  68. /*
  69. =============
  70. CG_AutomapDown_f
  71. =============
  72. */
  73. static void CG_AutomapDown_f( void ) 
  74. {
  75.     cg.showAutomap = qtrue;
  76. }
  77.  
  78. /*
  79. =============
  80. CG_AutomapUp_f
  81. =============
  82. */
  83. static void CG_AutomapUp_f( void ) 
  84. {
  85.     cg.showAutomap = qfalse;
  86. }
  87.  
  88. /*
  89. =============
  90. CG_ReloadHud_f
  91. =============
  92. */
  93. static void CG_ReloadHud_f ( void )
  94. {
  95.     // Reset the string table used for menus  
  96.     String_Init();
  97.  
  98.     // Clear all menus
  99.     Menu_Reset();
  100.     
  101.     // Reload the menus
  102.     CG_LoadMenus ( "ui/hud.txt" );
  103. }
  104.  
  105. /*
  106. =============
  107. CG_Radio_f
  108.  
  109. Bring up the radio menu if all the conditions are met
  110. =============
  111. */
  112. static void CG_Radio_f ( void )
  113. {
  114.     // Only in team games
  115.     if ( !cgs.gametypeData->teams )
  116.     {
  117.         return;
  118.     }
  119.  
  120.     // Not when ghosting or following
  121.     if ( cg.snap->ps.pm_flags & (PMF_FOLLOW|PMF_GHOST) )
  122.     {
  123.         return;
  124.     }
  125.  
  126.     // Not when a spectator
  127.     if ( cg.snap->ps.pm_type == PM_SPECTATOR )
  128.     {
  129.         return;
  130.     }
  131.  
  132.     trap_UI_SetActiveMenu ( UIMENU_RADIO );
  133. }
  134.  
  135. /*
  136. =============
  137. CG_Objectives_f
  138.  
  139. Bring up the objectives menu if all the conditions are met
  140. =============
  141. */
  142. static void CG_Objectives_f ( void )
  143. {
  144.     // Dont bother popping up the objectives dialog if there is
  145.     // no objective text
  146.     if ( !cgs.gametypeData->description )
  147.     {
  148.         return;
  149.     }
  150.  
  151.     trap_UI_SetActiveMenu ( UIMENU_OBJECTIVES );
  152. }
  153.  
  154. /*
  155. =============
  156. CG_Outfitting_f
  157.  
  158. Bring up the outfitting menu if all the conditions are met
  159. =============
  160. */
  161. static void CG_Outfitting_f ( void )
  162. {
  163.     // Only allow outfitting when pickups are disabled
  164.     if ( !cgs.pickupsDisabled )
  165.     {
  166.         return;
  167.     }
  168.  
  169.     trap_UI_SetActiveMenu ( UIMENU_OUTFITTING );
  170. }
  171.  
  172. /*
  173. =============
  174. CG_Team_f
  175.  
  176. bring up the team selection user interface
  177. =============
  178. */
  179. static void CG_Team_f ( void )
  180. {
  181.     // No team menu in non-team games
  182.     if ( !cgs.gametypeData->teams )
  183.     {
  184.         return;
  185.     }
  186.  
  187.     // Special case which only brings up the team menu if its the clients first
  188.     // time to the objectives dialog
  189.     if ( atoi ( CG_Argv(1) ) )
  190.     {
  191.         if ( ui_info_seenobjectives.integer )
  192.         {
  193.             return;
  194.         }
  195.     }
  196.  
  197.     CG_UpdateTeamCountCvars ( );
  198.  
  199.     trap_Cvar_Set ( "ui_info_seenobjectives", "1" );
  200.     trap_UI_SetActiveMenu ( UIMENU_TEAM );
  201. }
  202.  
  203. /*
  204. =============
  205. CG_Drop_f
  206.  
  207. Drops the selected weapon
  208. =============
  209. */
  210. void CG_Drop_f ( void ) 
  211. {
  212.     char    cmd[128];
  213.     int        exclude;
  214.  
  215.     // Cant drop when following or a ghost
  216.     if ( cg.snap->ps.pm_flags & (PMF_FOLLOW|PMF_GHOST) )
  217.     {
  218.         return;
  219.     }
  220.  
  221.     // Either dead or spectating if not normal
  222.     if ( cg.predictedPlayerState.pm_type != PM_NORMAL )
  223.     {
  224.         return;
  225.     }
  226.  
  227.     // Can only drop a weapon when in ready state
  228.     if ( cg.predictedPlayerState.weaponstate != WEAPON_READY )
  229.     {
  230.         return;
  231.     }
  232.  
  233.     // Cant drop the knife
  234.     if( cg.weaponSelect == WP_KNIFE )
  235.     {
  236.         return;
  237.     }
  238.  
  239.     // Close the menu since a weapon is being dropped
  240.     cg.weaponMenuUp = qfalse;
  241.  
  242.     // Build the server command        
  243.     Com_sprintf( cmd, 128, "drop %i", cg.weaponSelect );
  244.  
  245.     // Go to next weapon before the current drops
  246.     exclude = cg.weaponSelect;
  247.     cg.weaponSelect = WP_M84_GRENADE;
  248.     CG_PrevWeapon ( qfalse, exclude );
  249.  
  250.     // Send server comand
  251.     trap_SendClientCommand( cmd );
  252. }
  253.  
  254. /*
  255. =============
  256. CG_GetOutfittingGroupFromString
  257.  
  258. Converts the given string into an outfitting group id
  259. =============
  260. */
  261. static int CG_GetOutfittingGroupFromString ( const char* str )
  262. {
  263.     if ( Q_stricmp ( str, "primary" ) == 0 )
  264.     {
  265.         return OUTFITTING_GROUP_PRIMARY;
  266.     }
  267.     else if ( Q_stricmp ( str, "secondary" ) == 0 )
  268.     {
  269.         return OUTFITTING_GROUP_SECONDARY;
  270.     }
  271.     else if ( Q_stricmp ( str, "pistol" ) == 0 )
  272.     {
  273.         return OUTFITTING_GROUP_PISTOL;
  274.     }
  275.     else if ( Q_stricmp ( str, "grenade" ) == 0 )
  276.     {
  277.         return OUTFITTING_GROUP_GRENADE;
  278.     }
  279.     else if ( Q_stricmp ( str, "knife" ) == 0 )
  280.     {
  281.         return OUTFITTING_GROUP_KNIFE;
  282.     }
  283.  
  284.     return -1;
  285. }
  286.  
  287. /*
  288. =============
  289. CG_WeaponToggle_f
  290.  
  291. toggles between multiple weapons
  292. =============
  293. */
  294. static void CG_WeaponToggle_f ( void )
  295. {
  296.     int            group1;
  297.     int            group2;
  298.     int            weapon1;
  299.     int            weapon2;
  300.     gitem_t*    item;
  301.     int            i;
  302.  
  303.     if ( !cg.snap ) 
  304.     {
  305.         return;
  306.     }
  307.     
  308.     if ( cg.predictedPlayerState.stats[STAT_USEWEAPONDROP] )
  309.     {
  310.         return;
  311.     }
  312.  
  313.     if ( cg.snap->ps.pm_flags & PMF_FOLLOW ) 
  314.     {
  315.         return;
  316.     }
  317.  
  318.     if ( cg.predictedPlayerState.weaponstate == WEAPON_CHARGING     || 
  319.          cg.predictedPlayerState.weaponstate == WEAPON_CHARGING_ALT    ) 
  320.     {
  321.         return;
  322.     }
  323.  
  324.     // Get the toggle groups
  325.     group1 = CG_GetOutfittingGroupFromString ( CG_Argv(1) );
  326.     group2 = CG_GetOutfittingGroupFromString ( CG_Argv(2) );
  327.  
  328.     // Invalid toggle if either is -1
  329.     if ( group1 == -1 ) // || group2 == -1 )
  330.     {
  331.         return;
  332.     }
  333.  
  334.     // Make sure they have something from both of the groups
  335.     weapon1 = WP_NONE;
  336.     weapon2 = WP_NONE;
  337.     for ( i = WP_KNIFE; i < WP_NUM_WEAPONS; i ++ )
  338.     {    
  339.         // Make sure this weapon is selectable.
  340.         if ( !CG_WeaponSelectable ( i, qtrue ) )
  341.         {
  342.             continue;
  343.         }
  344.  
  345.         item = BG_FindWeaponItem ( i );
  346.         if ( item->outfittingGroup == group1 )
  347.         {
  348.             weapon1 = i;
  349.         }
  350.         else if ( item->outfittingGroup == group2 )
  351.         {
  352.             weapon2 = i;
  353.         }
  354.     }
  355.     
  356.     // IF only one of the two weapons is available then go to it
  357.     if ( weapon1 == WP_NONE && weapon2 == WP_NONE )
  358.     {
  359.         return;
  360.     }
  361.     else if ( weapon1 == WP_NONE )
  362.     {
  363.         cg.weaponSelect = weapon2;
  364.         return;
  365.     }
  366.     else if ( weapon2 == WP_NONE )
  367.     {
  368.         cg.weaponSelect = weapon1;
  369.         return;
  370.     }
  371.         
  372.     // They have both weapons, so figure out which to go to
  373.     item = BG_FindWeaponItem ( cg.weaponSelect );
  374.  
  375.     if ( item->outfittingGroup == group1 )
  376.     {
  377.         cg.weaponSelect = weapon2;
  378.     }
  379.     else
  380.     {
  381.         cg.weaponSelect = weapon1;
  382.     }
  383. }
  384.  
  385. /*
  386. =============
  387. CG_NextWeapon_f
  388.  
  389. selects next weapon in inventory and allows empty weapons to
  390. be selected
  391. =============
  392. */
  393. static void CG_NextWeapon_f ( void )
  394. {
  395.     if ( cg_zoomWeaponChange.integer && (cg.predictedPlayerState.pm_flags & PMF_ZOOMED ) )
  396.     {
  397.         trap_SendConsoleCommand ( "+zoomin; wait; -zoomin;" );
  398.         return;
  399.     }
  400.  
  401.     CG_NextWeapon ( qtrue, -1 );
  402. }
  403.  
  404. /*
  405. =============
  406. CG_PrevWeapon_f
  407.  
  408. selects previous weapon in inventory and allows empty weapons
  409. to be selectd
  410. =============
  411. */
  412. static void CG_PrevWeapon_f ( void )
  413. {
  414.     if ( cg_zoomWeaponChange.integer && (cg.predictedPlayerState.pm_flags & PMF_ZOOMED) )
  415.     {
  416.         trap_SendConsoleCommand ( "+zoomout; wait; -zoomout;" );
  417.         return;
  418.     }
  419.  
  420.     CG_PrevWeapon ( qtrue, -1 );
  421. }
  422.  
  423. /*
  424. =============
  425. CG_LastWeapon_f
  426.  
  427. Selects the last weapon that was selected
  428. =============
  429. */
  430. static void CG_LastWeapon_f ( void )
  431. {
  432.     if ( CG_WeaponSelectable ( cg.weaponLastSelect, qtrue ) )
  433.     {
  434.         int swap = cg.weaponSelect;
  435.         cg.weaponSelect = cg.weaponLastSelect;
  436.         cg.weaponLastSelect = swap;
  437.     }
  438. }
  439.  
  440.  
  441. static void CG_TellTarget_f( void ) {
  442.     int        clientNum;
  443.     char    command[128];
  444.     char    message[128];
  445.  
  446.     clientNum = CG_CrosshairPlayer();
  447.     if ( clientNum == -1 ) {
  448.         return;
  449.     }
  450.  
  451.     trap_Args( message, 128 );
  452.     Com_sprintf( command, 128, "tell %i %s", clientNum, message );
  453.     trap_SendClientCommand( command );
  454. }
  455.  
  456. static void CG_TellAttacker_f( void ) {
  457.     int        clientNum;
  458.     char    command[128];
  459.     char    message[128];
  460.  
  461.     clientNum = CG_LastAttacker();
  462.     if ( clientNum == -1 ) {
  463.         return;
  464.     }
  465.  
  466.     trap_Args( message, 128 );
  467.     Com_sprintf( command, 128, "tell %i %s", clientNum, message );
  468.     trap_SendClientCommand( command );
  469. }
  470.  
  471. /*
  472. ==================
  473. CG_StartOrbit_f
  474. ==================
  475. */
  476.  
  477. static void CG_StartOrbit_f( void ) {
  478.     char var[MAX_TOKEN_CHARS];
  479.  
  480.     trap_Cvar_VariableStringBuffer( "developer", var, sizeof( var ) );
  481.     if ( !atoi(var) ) {
  482.         return;
  483.     }
  484.     if (cg_cameraOrbit.value != 0) {
  485.         trap_Cvar_Set ("cg_cameraOrbit", "0");
  486.         trap_Cvar_Set("cg_thirdPerson", "0");
  487.     } else {
  488.         trap_Cvar_Set("cg_cameraOrbit", "5");
  489.         trap_Cvar_Set("cg_thirdPerson", "1");
  490.         trap_Cvar_Set("cg_thirdPersonAngle", "0");
  491.         trap_Cvar_Set("cg_thirdPersonRange", "100");
  492.     }
  493. }
  494.  
  495. typedef struct 
  496. {
  497.     char    *cmd;
  498.     void    (*function)(void);
  499.  
  500. } consoleCommand_t;
  501.  
  502. static consoleCommand_t    commands[] = 
  503. {
  504.     { "testmodel",        CG_TestModel_f            },
  505.     { "nextframe",        CG_TestModelNextFrame_f },
  506.     { "prevframe",        CG_TestModelPrevFrame_f },
  507.     { "nextskin",        CG_TestModelNextSkin_f    },
  508.     { "prevskin",        CG_TestModelPrevSkin_f    },
  509.     { "viewpos",        CG_Viewpos_f            },
  510.     { "+scores",        CG_ScoresDown_f            },
  511.     { "-scores",        CG_ScoresUp_f            },
  512.     { "+automap",        CG_AutomapDown_f        },
  513.     { "-automap",        CG_AutomapUp_f            },
  514.     { "weapnext",        CG_NextWeapon_f            },
  515.     { "weapprev",        CG_PrevWeapon_f            },
  516.     { "weaplast",        CG_LastWeapon_f            },
  517.     { "weapon",            CG_Weapon_f                },
  518.     { "tell_target",    CG_TellTarget_f            },
  519.     { "tell_attacker",    CG_TellAttacker_f        },
  520.     { "reloadhud",        CG_ReloadHud_f            },
  521.     { "startOrbit",        CG_StartOrbit_f            },
  522.     { "loaddeferred",    CG_LoadDeferredPlayers    },
  523.     { "drop",            CG_Drop_f                },
  524.  
  525.     { "weaptoggle",        CG_WeaponToggle_f        },
  526.  
  527.     { "ui_radio",        CG_Radio_f },
  528.     { "ui_objectives",    CG_Objectives_f },
  529.     { "ui_outfitting",    CG_Outfitting_f },
  530.     { "ui_team",        CG_Team_f },
  531. };
  532.  
  533. /*
  534. =================
  535. CG_ConsoleCommand
  536.  
  537. The string has been tokenized and can be retrieved with
  538. Cmd_Argc() / Cmd_Argv()
  539. =================
  540. */
  541. qboolean CG_ConsoleCommand( void ) 
  542. {
  543.     const char    *cmd;
  544.     int        i;
  545.  
  546.     // No console commands when a map is changing
  547.     if ( cg.mMapChange )
  548.     {
  549.         return qfalse;
  550.     }
  551.  
  552.     cmd = CG_Argv(0);
  553.  
  554.     for ( i = 0 ; i < sizeof( commands ) / sizeof( commands[0] ) ; i++ ) 
  555.     {
  556.         if ( !Q_stricmp( cmd, commands[i].cmd ) ) 
  557.         {
  558.             commands[i].function();
  559.             return qtrue;
  560.         }
  561.     }
  562.  
  563.     return qfalse;
  564. }
  565.  
  566. /*
  567. =================
  568. CG_InitConsoleCommands
  569.  
  570. Let the client system know about all of our commands
  571. so it can perform tab completion
  572. =================
  573. */
  574. void CG_InitConsoleCommands( void ) 
  575. {
  576.     int        i;
  577.  
  578.     for ( i = 0 ; i < sizeof( commands ) / sizeof( commands[0] ) ; i++ ) 
  579.     {
  580.         trap_AddCommand( commands[i].cmd );
  581.     }
  582.  
  583.     //
  584.     // the game server will interpret these commands, which will be automatically
  585.     // forwarded to the server after they are not recognized locally
  586.     //
  587.     trap_AddCommand ("kill");
  588.     trap_AddCommand ("say");
  589.     trap_AddCommand ("say_team");
  590.     trap_AddCommand ("tell");
  591.     trap_AddCommand ("vsay_team");
  592.     trap_AddCommand ("give");
  593.     trap_AddCommand ("god");
  594.     trap_AddCommand ("notarget");
  595.     trap_AddCommand ("noclip");
  596.     trap_AddCommand ("team");
  597.     trap_AddCommand ("follow");
  598.     trap_AddCommand ("levelshot");
  599. #ifdef _SOF2_BOTS
  600.     trap_AddCommand ("addbot");
  601. #endif
  602.     trap_AddCommand ("setviewpos");
  603.     trap_AddCommand ("callvote");
  604.     trap_AddCommand ("vote");
  605.     trap_AddCommand ("stats");
  606.     trap_AddCommand ("teamtask");
  607.     trap_AddCommand ("loaddeferred");
  608.     trap_AddCommand ("gametype_restart");
  609. }
  610.